
; flat assembler core
; Copyright (c) 1999-2007, Tomasz Grysztar.
; All rights reserved.

formatter:
	pusha
my_common_formatter:
;stdcall prhex,edi
;stdcall prhex,[code_start]

		mov al,0e9h	;jmp near +offset
		stosb		;1
		mov eax,edi
		sub eax,[code_start]
		sub eax,1+1+4-4
		neg eax		;-offset return point
		stosd		;4


	mov	eax,edi
	sub	eax,[code_start]
	mov	[real_code_size],eax
push edi
mov edi,[code_start]
inc edi
inc edi
stosd
pop edi

	cmp	edi,[undefined_data_end]
	jne	my_calculate_code_size
	mov	edi,[undefined_data_start]
my_calculate_code_size:
	sub	edi,[code_start]
	mov	[code_size],edi
;mov eax,[lpCodeSize]
;mov [eax],edi
	mov	[written_size],0
;	mov	edx,[output_file]
;	call	create

my_write_code:
;	mov	eax,[written_size]
;	mov	[headers_size],eax

stdcall module_interface_create,[current_module],[code_size]

add ecx,[code_size]
mov [code_size],ecx

mov ebx,[lpCodeSize]
mov [ebx],ecx


push ecx ;[code_size]
call getMem

;push ecx
;push [code_start]
;call regetMem
;add esp,4*2
;mov [code_start],eax

mov ebx,[lpCompiledCode]
;mov eax,[code_start]
mov [ebx],eax

push [code_size]	;size
push [code_start]	;from
push eax		;to
call cpyMem
add esp,(4*3)+(4*1)


;	mov edx,[output_file]
;	call create
;
;	mov	edx,[code_start]
;	mov	ecx,[code_size]
;	add	[written_size],ecx
;	call	write
;
;	call close

	popa
	ret

